var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2BundleManager = require("BundleManager");
var $2DataManager = require("DataManager");
var $2FlbMathUtil = require("FlbMathUtil");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_Jiangshi = /* */function (_cc$Component30) {
  babel_inherits(c, _cc$Component30);
  var _super34 = babel_createSuper(c);
  function c() {
    var _this74;
    babel_classCallCheck(this, c);
    _this74 = _super34.apply(this, arguments);
    _this74.dragon = null;
    _this74.speed = 100;
    _this74.player = null;
    _this74.dir = cc.v2();
    _this74.type = 0;
    return _this74;
  }
  babel_createClass(c, [{
    key: "onLoad",
    value: function onLoad() {
      this.dragon = this.node.getComponent(sp.Skeleton);
      this.setSkin();
      this.player = cc.find("PlayerBall", this.node.parent.parent.parent);
      var e = this.player.parent.convertToWorldSpaceAR(this.player.position);
      var t = this.node.parent.convertToNodeSpaceAR(e).sub(this.node.position).normalize();
      this.dir = cc.v2(t.x, t.y);
      this.node.scaleX = -this.node.scaleX;
      var a = Math.atan2(this.dir.y, this.dir.x);
      var n = cc.misc.radiansToDegrees(a);
      this.node.scaleX = n > 90 && n < 180 || n < -90 && n > -180 ? .8 : -.8;
    }
  }, {
    key: "setType",
    value: function setType(e) {
      this.speed = e;
    }
  }, {
    key: "setSkin",
    value: function setSkin() {
      var _this75 = this;
      var e = [{
        path: "zombie/jiangshi/jiangshi",
        defaultSkin: "js",
        width: 72.3,
        height: 59.6,
        scale: .7
      }, {
        path: "zombie/p03/p03",
        defaultSkin: "default",
        width: 72.3,
        height: 59.6,
        scale: .7
      }, {
        path: "zombie/p05/p05",
        defaultSkin: "default",
        width: 86,
        height: 116.3,
        scale: .9
      }, {
        path: "zombie/p08/p08",
        defaultSkin: "default",
        width: 156.88,
        height: 211.36,
        scale: .7
      }, {
        path: "zombie/p10/p10",
        defaultSkin: "default",
        width: 155.3,
        height: 162.28,
        scale: .7
      }];
      var t = $2FlbMathUtil.MathUtil.getRandomInt(0, 4);
      if ($2BundleManager.default.instance.getBundleRes("Spine", e[t].path, sp.SkeletonData)) {
        this.dragon.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", e[t].path, sp.SkeletonData);
        this.dragon.defaultSkin = e[t].defaultSkin;
        this.dragon.setSkin(e[t].defaultSkin);
      } else {
        $2BundleManager.default.instance.loadBundleRes("Spine", e[t].path, sp.SkeletonData, function () {
          _this75.dragon.skeletonData = $2BundleManager.default.instance.getBundleRes("Spine", e[t].path, sp.SkeletonData);
          _this75.dragon.defaultSkin = e[t].defaultSkin;
          _this75.dragon.setSkin(e[t].defaultSkin);
        });
      }
      if (0 === t) {
        this.dragon.setAnimation(0, "zou", true);
        this.dragon.timeScale = 5;
      } else {
        this.dragon.setAnimation(0, "move", true);
        this.dragon.timeScale = 5;
      }
      this.node.width = e[t].width;
      this.node.height = e[t].height;
      this.node.scale = e[t].scale;
    }
  }, {
    key: "update",
    value: function update(e) {
      if ($2DataManager.default.instance.is_over) {
        return;
      }
      var t = this.dir.x * this.speed * e;
      var a = this.dir.y * this.speed * e;
      this.node.x += t;
      this.node.y += a;
      var n = Math.atan2(this.dir.y, this.dir.x);
      var i = cc.misc.radiansToDegrees(n);
      this.node.scaleX = i > 90 && i < 180 || i < -90 && i > -180 ? 1 : -1;
      this.node.position.sub(this.node.parent.position).mag() > cc.winSize.width + cc.winSize.height + 1e3 && this.node.removeFromParent();
    }
  }]);
  return c;
}(cc.Component);
def_Jiangshi = cc__decorate([ccp_ccclass], def_Jiangshi);
exports.default = def_Jiangshi;